<template>
	<view class="page bg-fff">
		<view class="topBannerWrap bg"></view>

		<view class="contentWrap">
			<view class="title font15 col-fff bg-theme text-center fontBold">{{ detailData.title }}</view>

			<view class="youhuiContent top-15">
				<view class="rowWrap flex">
					<view class="leftTit col-theme fontBold">购房优惠措施</view>
					<view class="rightTxt">{{ detailData.youhui || '--' }}</view>
				</view>
				<view class="rowWrap flex border-top-grey">
					<view class="leftTit col-theme fontBold">参与便民措施</view>
					<view class="rightTxt">{{ detailData.bianmin || '--' }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from "vue";
import { useUserInfoStore } from '@/store/index';
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
import { getDiscountDetail } from '@/common/api/tools';

const userInfoStore = useUserInfoStore();

let product_id = ref('');
let detailData = ref({});


// 页面加载
onLoad((options) => {
	product_id.value = options.productId;
	uni.$check_and_login(init)
})

// 分享到好友
onShareAppMessage(() => {
	return {
		title: detailData.value.title + '优惠信息' || '最新优惠信息',
		path: `/pages/tools/you-hui/detail/index?productId=${product_id.value}&puid=${userInfoStore.userInfo.id}`,
		imageUrl: '',
	}
})

// 分享到朋友圈
onShareTimeline(() => {
	return {
		title: detailData.value.title + '优惠信息' || '最新优惠信息',
		query: `productId=${product_id.value}&puid=${userInfoStore.userInfo.id}`
	}
})

//初始化
async function init() {
	try {
		const res = await getDiscountDetail(product_id.value);
		if(res.status !== 0) {
			uni.$u.toast(res.detail);
			return
		}
		uni.setNavigationBarTitle({
			title: `${res.detail.title}优惠信息`
		});
		detailData.value = res.detail;
		product_id.value = res.detail.id;
	} catch (error) {}
}
</script>

<style lang="scss" scoped>
.page{
	min-height: 100vh;
	overflow: hidden;
	padding: 0 28rpx;
	.topBannerWrap{
		margin: 28rpx 0;
		position: relative;
		height: 260rpx;
		background-image: url("https://image.srea.org.cn/xcx/zuixin-youhui-top-bg.jpg");
	}
	.contentWrap{
		.title{
			padding: 14rpx 0;
			line-height: 1.4;
		}
		.youhuiContent{
			border: 1px solid #E5E5E5;
			padding: 0 10rpx;
			.rowWrap{
				padding: 20rpx 0;
				justify-content: space-between;
				.leftTit{
					width: 200rpx;
				}
				.rightTxt{
					width: calc(100% - 230rpx);
				}
			}
		}
	}
}
</style>